/*
    jME Terra package. A Terrain Engine for the Java Monkey Engine.
    Copyright (C) 2005-2006,  Tijl Houtbeckers
    
    **** LICENSE: ****

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation,
	version 2.1.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

	**** CONTACT: ****

    I can be reached through the jmonkeyengine.com forums (user "llama"), 
    or the jmonkeyengine.com contact page:
    jmonkeyengine.com/index.php?option=com_contact&task=view&contact_id=5           

*/

/**
 * @author Tijl Houtbeckers
 */

package org.llama.jmex.terra;

public class XYKey {
    
	// The Grid coordinates of the block 
    public int x, y;
    public String key;
    protected int hashcode;
    
    public XYKey(int x, int y, String key) {
        update(x, y, key);
    }
    
    public XYKey(XYKey xy) {
    	x = xy.x;
    	y = xy.y;
    	key = xy.key;
    	hashcode = xy.hashcode;
    }
    
    public void update(int x, int y, String key) {
    	this.x = x;
        this.y = y;
        this.key = key;
        hashcode = x + (y * 46341) ^ ((key == null) ? 0 : key.hashCode());
    }
        
    public int hashCode() {
        return hashcode;
    }
    
    public boolean equals(Object o) {
        if (o instanceof XYKey) {
            XYKey xy = (XYKey) o;
            if (xy.x == x && xy.y == y && 
                    ((xy.key == null && key == null) || xy.key.equals(key)))
                return true;
        }
        return false;           
    }
    
    public boolean equals(XYKey xy){
    	if (xy.x == x && xy.y == y && xy.key.equals(key))
            return true;
    	return false;
    }
    
    public String toString() {
    	return "XYKey: "+x+":"+y+":"+key;
    }

}
